package com.youshang.designpattern.chain;

import com.google.common.base.Supplier;
import com.google.common.collect.Maps;
import com.youshang.designpattern.chain.handler.ConstructHandle;
import com.youshang.designpattern.chain.handler.HandleRequest;
import com.youshang.designpattern.chain.handler.HandleBase;

import java.lang.reflect.Type;
import java.util.HashMap;

public class Client {

    static HashMap<Type, Supplier<? extends HandleBase>> baseHashMap = Maps.newHashMap();
    static {
        baseHashMap.put(HandleA.class,HandleA::new);
        baseHashMap.put(HandleB.class,HandleB::new);
        baseHashMap.put(HandleC.class,HandleC::new);
        baseHashMap.put(HandleD.class,HandleD::new);
    }

    public static void main(String[] args) {

        //请求参数
        HandleRequest request = new HandleRequest();

        ConstructHandle constructHandle = new ConstructHandle(baseHashMap);
        HandleBase handler = constructHandle.createHandler(HandleA.class, HandleB.class, HandleC.class, HandleD.class);
        handler.getHead().start(request);
    }
}
